﻿/**
 * Copyright © TnT-VNGroup 2011
 * PROJECT:   SmartCollector
 * $HeadURL: http://smartcollector.googlecode.com/svn/branches/Srcs/SmartCollector.HtmlParser/Utilities/Attribute.cs $
 * $Author: chithanh12@gmail.com $
 * $Date: 2011-04-20 18:46:52 +0000 (Wed, 20 Apr 2011) $
 * $Rev: 94 $
 **/
namespace HtmlParser
{
    public class Attribute
    {
        #region Field
        private string m_name;
        private string m_value;
        private char m_delim;
        #endregion

        #region Properties
        /// <summary>
        /// Gets or sets the name of the attribute.
        /// </summary>
        /// <value>The name of the attribute.</value>
        /// 
        public string Name
        {
            get
            {
                return this.m_name;
            }
            set
            {
                this.m_name = value;
            }
        }

        /// <summary>
        /// Gets or sets the attribute value.
        /// </summary>
        /// <value>The attribute value.</value>
        public string Value
        {
            get
            {
                return this.m_value;
            }
            set
            {
                this.m_value = value;
            }
        }

        /// <summary>
        /// Gets or sets the attribute delim.
        /// </summary>
        /// <value>The attribute delim.</value>
        public char Delim
        {
            get
            {
                return this.m_delim;
            }
            set
            {
                this.m_delim = value;
            }
        }

        #endregion

        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="Attribute"/> class.
        /// </summary>
        /// <param name="name">Name of the attribute.</param>
        /// <param name="val">The val.</param>
        /// <param name="delim">The attribute delim.</param>
        public Attribute(string name, string val, char delim)
        {
            this.m_name = name;
            this.m_value = val;
            this.m_delim = delim;
        }
        #endregion

        #region Methods
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            if (m_value==null ||m_value==string.Empty)
            {
                return m_name;
            }
            if(m_delim== (char)0)
            {
                return string.Format("{0}={1}",m_name,m_value);
            }

            return string.Format("{0}={1}{2}{1}",m_name,m_delim,m_value);
        }
        #endregion
    }
}
